﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TrainingsApp.WebModel;
using TrainingsApp.Logic;
using TrainingsApp.Model;
using ZJFramework10.Extension;
namespace TrainingsApp.IPADApp {
    public partial class AnalysisPieMap : AccountPage {


        //public Guid PreviewId { get { return new Guid(ZJFramework10.Utility.QueryStringManager.GetValue<string>("pid", Guid.Empty.ToString())); } }
        //public long ClassId { get { return ZJFramework10.Utility.QueryStringManager.GetValue<Int64>("cid"); } }

        public string[] Data {
            get {

                return ZJFramework10.Utility.QueryStringManager.GetValue<string>("per", "").Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
            }
        }

        protected void Page_Load(object sender, EventArgs e) {

            List<TS_Preview_Result_Entity> resultList = new List<TS_Preview_Result_Entity>();

            int i = 0;
            foreach (var item in Data) {
                i++;
                resultList.Add(new TS_Preview_Result_Entity {
                    ReferencePercent = item.AsDouble(0.0),
                    GroupId = i
                });
            }

            double[] yval = new double[resultList.Count];
            string[] xval = new string[resultList.Count];

             i = 0;
            foreach (var item in resultList.OrderByDescending(u => u.ReferencePercent)) {
                yval[i] = item.ReferencePercent;
                xval[i] = item.GroupName.ToString();
                i++;
            }

            this.Chart1.Series["Series1"].Points.DataBindXY(xval, yval);

            var colorManager = ChartColorManager.GetInstance();
            for (int j = 0; j < this.Chart1.Series["Series1"].Points.Count; j++) {
                this.Chart1.Series["Series1"].Points[j].Color = colorManager.GetColor();
            }
        }

        public override WebModel.Other.AccountMenuType MenuType {
            get { return WebModel.Other.AccountMenuType.Preview; }
        }
    }
}